package edu.towson.cis.cosc442.project3.vendingmachine2;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class VendingMachineItemTest {
	VendingMachineItem item;
	@Before
	public void setUp() throws Exception {
		item = new VendingMachineItem("cake",1.0);
		VendingMachineException e= new VendingMachineException();
	}

	@After
	public void tearDown() throws Exception {
		item=null;
	}

	/*
	 * Tests the constructor to see if a newly created 
	 * item is not null and the values are correct
	 */
	@Test
	public void testVendingMachineItem() {
		String name="pie";
		double price=1.25;
		VendingMachineItem result = new VendingMachineItem(name,price);
		assertNotNull(result);
		assertEquals(price,result.getPrice(),.01);
		assertSame(name,result.getName());
	}
	
	//Tests the item creation failure route
	@Test (expected=VendingMachineException.class)
	public void testVendingMachineItemException() {
		VendingMachineItem item2 = new VendingMachineItem("pie",-1);
	}

	//tests the getter for name
	@Test
	public void testGetName() {
		assertSame("cake",item.getName());
	}

	//tests the getter for price
	@Test
	public void testGetPrice() {
		assertEquals(1.0,item.getPrice(),.1);
	}

}
